using UnityEngine;
using System.Collections;

public class ball : MonoBehaviour {

	public float speed = 7.0f;
	public float kimpoaminen=2-0f;
	public float startspeed = 0.0f;
	public bool started = false;
	public GUIStyle tyyli;
	void OnGUI () {GUI.Box(new Rect(0,0,100,startspeed*35),"",tyyli);
	
	}
	// Use this for initialization
	void Start () {
		
		//alkuvauhti
		
		//rigidbody.velocity = new Vector3(0.0f, -speed, 0.2f);
		
		
			
		
	
	}
	
	// Update is called once per frame
	void Update () {
		
		if(started==false)
		{
			
				
			if(Input.GetKey("space"))
			{
				startspeed+=Time.deltaTime*10;
			}
			
			if(Input.GetKeyUp("space"))
			{
				started=true;
				rigidbody.velocity = new Vector3(0.0f, startspeed, 0.2f);
			startspeed+=speed;
				
			}
		}	
			
			
			
		//pitää nopeuden vakiona
		
		if(started==true)
		rigidbody.velocity = rigidbody.velocity.normalized * startspeed;
		
			
		
	}
	
	
	void OnCollisionEnter(Collision c)
		 {
		
		//lisätään suuntaa satunnaisesti ettei jää jumii mihinkään
		 
		rigidbody.velocity += new Vector3(Random.Range (-kimpoaminen,kimpoaminen), Random.Range (-kimpoaminen,kimpoaminen), 0.0f);
		
			
			//tuhotaan pallo jos osuu lattiaaan
		
		if(c.gameObject.name=="floor")
			Destroy (gameObject);
		
}
}